<?php

namespace App\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
use MenuService;
use PermissionService;
use Auth;

class PermissionController extends Controller
{
    public function edit()
    {
        PermissionService::generate();//生成权限表
        $permissions = include config_path() . '/permissions.php';
        return $permissions;
    }


    public function update(Request $request, Role $role)
    {
        $role->syncPermissions($request->input('permissions'));

        return $this->message('权限修改成功');
    }

    /**
     * 当前管理员所有权限
     */
    public function admin()
    {
        $permissions = Auth::user()->getAllPermissions()->pluck('name');
        return $permissions;
    }

}
